﻿using Konves.Scripture;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Konves.Scripture.Data;

namespace Konves.Scripture.Tests
{
    /// <summary>
    ///This is a test class for ReferenceInfoTest and is intended
    ///to contain all ReferenceInfoTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ReferenceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        public void ParseTest_Single()
        {
            string reference = "John 3:16";
            RepositoryMode mode = RepositoryMode.Safe;
            Reference expected = new Reference();

            expected.Add(new Range
            {
                Start = new Verse
                {
                    BookName = "John",
                    BookId = 43,
                    ChapterNumber = 3,
                    Index = 26126,
                    Suffix = null,
                    VerseNumber = 16
                },
                End = new Verse
                {
                    BookName = "John",
                    BookId = 43,
                    ChapterNumber = 3,
                    Index = 26126,
                    Suffix = null,
                    VerseNumber = 16
                }
            });
                
            Reference actual;
            actual = Reference.Parse(reference, mode);

            Reference.EqualityComparer eq = new Reference.EqualityComparer();
            Assert.IsTrue(eq.Equals(expected, actual));

        }

        [TestMethod()]
        public void ParseTest_MultipleVerses()
        {
            string reference = "john 3:16-18,20";
            Reference expected = new Reference();
            expected.Add(new Range
            {
                Start = new Verse
                {
                    BookName = "John",
                    BookId = 43,
                    ChapterNumber = 3,
                    Index = 26126,
                    Suffix = null,
                    VerseNumber = 16
                },
                End = new Verse
                {
                    BookName = "John",
                    BookId = 43,
                    ChapterNumber = 3,
                    Index = 26128,
                    Suffix = null,
                    VerseNumber = 18
                }
            });

            expected.Add(new Range
            {
                Start = new Verse
                {
                    BookName = "John",
                    BookId = 43,
                    ChapterNumber = 3,
                    Index = 26130,
                    Suffix = null,
                    VerseNumber = 20
                },
                End = new Verse
                {
                    BookName = "John",
                    BookId = 43,
                    ChapterNumber = 3,
                    Index = 26130,
                    Suffix = null,
                    VerseNumber = 20
                }
            });

            Reference actual;
            actual = Reference.Parse(reference);

            Reference.EqualityComparer eq = new Reference.EqualityComparer();
            Assert.IsTrue(eq.Equals(expected, actual));

        }

        [TestMethod()]
        public void ParseTest_MultipleChaptersAndVerses()
        {
            string reference = "john 3:16-18,4:15-16";
            Reference expected = new Reference();
            expected.Add(new Range
            {
                Start = new Verse
                {
                    BookName = "John",
                    BookId = 43,
                    ChapterNumber = 3,
                    Index = 26126,
                    Suffix = null,
                    VerseNumber = 16
                },
                End = new Verse
                {
                    BookName = "John",
                    BookId = 43,
                    ChapterNumber = 3,
                    Index = 26128,
                    Suffix = null,
                    VerseNumber = 18
                }
            });

            expected.Add(new Range
            {
                Start = new Verse
                {
                    BookName = "John",
                    BookId = 43,
                    ChapterNumber = 4,
                    Index = 26161,
                    Suffix = null,
                    VerseNumber = 15
                },
                End = new Verse
                {
                    BookName = "John",
                    BookId = 43,
                    ChapterNumber = 4,
                    Index = 26162,
                    Suffix = null,
                    VerseNumber = 16
                }
            });

            Reference actual;
            actual = Reference.Parse(reference);

            Reference.EqualityComparer eq = new Reference.EqualityComparer();
            Assert.IsTrue(eq.Equals(expected, actual));

        }

        [TestMethod()]
        public void ToStringTest_1()
        {
            Reference target = Reference.Parse("Gen 1:1, rom 5:8");
            string expected = "Genesis 1:1; Romans 5:8";
            string actual;
            actual = target.ToString();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void ToStringTest_2()
        {
            Reference target = Reference.Parse("Gen 1:1; gen 1:3");
            string expected = "Genesis 1:1,3";
            string actual;
            actual = target.ToString();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void ToStringTest_3()
        {
            Reference target = Reference.Parse("Gen 1:1, 3-5");
            string expected = "Genesis 1:1,3-5";
            string actual;
            actual = target.ToString();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void ToStringTest_4()
        {
            Reference target = Reference.Parse("Gen 1:1, 5:3");
            string expected = "Genesis 1:1,5:3";
            string actual;
            actual = target.ToString();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void ToStringTest_5()
        {
            Reference target = Reference.Parse("Gen 1:1, 5:3-13");
            string expected = "Genesis 1:1,5:3-13";
            string actual;
            actual = target.ToString();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void ToStringTest_6()
        {
            Reference target = Reference.Parse("Gen 1:1,3-5:8");
            string expected = "Genesis 1:1,3-5:8";
            string actual;
            actual = target.ToString();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void ToStringTest_7()
        {
            Reference target = Reference.Parse("Gen 1:1,3- romans 5:8");
            string expected = "Genesis 1:1,3 - Romans 5:8";
            string actual;
            actual = target.ToString();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void ToStringTest_8()
        {
            Reference target = Reference.Parse("Gen 1:1, 5:3-6:1");
            string expected = "Genesis 1:1,5:3-6:1";
            string actual;
            actual = target.ToString();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void ToStringTest_9()
        {
            Reference target = Reference.Parse("Gen 1:1, 5:3- romans 6:1");
            string expected = "Genesis 1:1,5:3 - Romans 6:1";
            string actual;
            actual = target.ToString();
            Assert.AreEqual(expected, actual);
        }
    }
}
